package cdu.xjj.service.impl;


import cdu.xjj.mapper.DeptMapper;
import cdu.xjj.pojo.Dept;
import cdu.xjj.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;


@Service
public class DeptServiceImpl implements DeptService {

    @Autowired
    private DeptMapper deptMapper;


    //查找所有部门信息
    @Override
    public List<Dept> findAll() {
        return deptMapper.findAll();
    }

    //按id删除部门
    @Override
    public void deteleById(Integer id) {
        deptMapper.deleteById(id);
    }

    @Override
    public void add(Dept dept) {
        //1：补全信息
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.insert(dept);
    }

    @Override
    public Dept getById(Integer id) {
       return deptMapper.getById(id);

    }

    @Override
    public void update(Dept dept) {
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.update(dept);
    }
}
